<?php

namespace Yj\Generator\Core\Model;

/**
 * @Notes: []
 * @User: zwc
 * @Date: 2022/3/1 19:45
 */
class VirtualPropertyModel extends BasePropertyModel
{

    /**
     * @var string
     */
    protected $type;

    /**
     * @return string
     */
    public function getType(): string
    {
        return $this->type;
    }

    /**
     * @param string $type
     */
    public function setType(string $type)
    {
        $this->type = $type;
        return $this;
    }

    /**
     * @var boolean
     */
    protected $readable = true;


    /**
     * @var boolean
     */
    protected $writable = true;

    /**
     * VirtualPropertyModel constructor.
     * @param string $name
     * @param string $type
     */
    public function __construct($name, $type = null)
    {
        $this->setName($name)
            ->setType($type);
    }


    /**
     * {@inheritDoc}
     */
    public function toLines()
    {
        $property = '@property';
        if (!$this->readable) {
            $property .= '-write';
        } elseif (!$this->writable) {
            $property .= '-read';
        }

        if ($this->type !== null) {
            $property .= ' ' . $this->type;
        }

        return $property . ' $' . $this->name;
    }


}